#ifndef UNP_H
#define UNP_H

#include <sys/socket.h>
#include <errno.h>
#include <sys/poll.h>
#include <stdarg.h>
#include <syslog.h>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <unistd.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <netdb.h>
#include <pthread.h>

#define	MAXLINE		4096
#define	SA	struct sockaddr

int Accept(int fd, struct sockaddr *sa, socklen_t *salenptr);
void Bind(int fd, const struct sockaddr *sa, socklen_t salen);
void Connect(int fd, const struct sockaddr *sa, socklen_t salen);
void Listen(int fd, int backlog);
int Poll(struct pollfd *fdarray, unsigned long nfds, int timeout);
ssize_t Recv(int fd, void *ptr, size_t nbytes, int flags);
ssize_t Recvfrom(int fd, void *ptr, size_t nbytes, int flags, struct sockaddr *sa, socklen_t *salenptr);
int Select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
void Send(int fd, const void *ptr, size_t nbytes, int flags);
void Sendto(int fd, const void *ptr, size_t nbytes, int flags, const struct sockaddr *sa, socklen_t salen);
void Setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen);
int Socket(int family, int type, int protocol);
void err_sys(const char *fmt, ...);
int Open(const char *pathname, int oflag, ...);
void Close(int fd);
ssize_t Read(int fd, void *ptr, size_t nbytes);
void Write(int fd, void *ptr, size_t nbytes);
pid_t Waitpid(pid_t pid, int *iptr, int options);
pid_t Fork(void);
int Fcntl(int fd, int cmd, int arg);
void Writen(int fd, void *ptr, size_t nbytes);
ssize_t Readn(int fd, void *ptr, size_t nbytes);
int Udp_client(const char *host, const char *serv, SA **saptr, socklen_t *lenptr);
int Udp_server(const char *host, const char *serv, socklen_t *addrlenp);
void err_quit(const char *fmt, ...);
void * Malloc(size_t size);

void Pthread_create(pthread_t *tid, const pthread_attr_t *attr, void * (*func)(void *), void *arg);
void Pthread_join(pthread_t tid, void **status);
void Pthread_detach(pthread_t tid);
void Pthread_kill(pthread_t tid, int signo);
void Pthread_mutexattr_init(pthread_mutexattr_t *attr);
#ifdef	_POSIX_THREAD_PROCESS_SHARED
void Pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int flag);
#endif
void Pthread_mutex_init(pthread_mutex_t *mptr, pthread_mutexattr_t *attr);
void Pthread_mutex_lock(pthread_mutex_t *mptr);
void Pthread_mutex_unlock(pthread_mutex_t *mptr);
void Pthread_cond_broadcast(pthread_cond_t *cptr);
void Pthread_cond_signal(pthread_cond_t *cptr);
void Pthread_cond_wait(pthread_cond_t *cptr, pthread_mutex_t *mptr);
void Pthread_cond_timedwait(pthread_cond_t *cptr, pthread_mutex_t *mptr, const struct timespec *tsptr);
void Pthread_once(pthread_once_t *ptr, void (*func)(void));
void Pthread_key_create(pthread_key_t *key, void (*func)(void *));
void Pthread_setspecific(pthread_key_t key, const void *value);
		
#endif //UNP_H
